class BTHud extends Hud;

var texture bt_crosshair, bt_health, bt_ammo;
var Font bt_font;
var() Material BoxMaterial;


function DrawHud( canvas canvas )
{

}

// Constantly called throughout to render HUD.
// The canvas is our screen, we draw to this and we can retrieve
// information from it such as the screen size.
function PostRender( canvas Canvas )
{
    super.PostRender(canvas);

    // Only draw if the player exists (spawned), we dont to before.
    if(Level.GetLocalPlayerController().Pawn != none)
    {
        // Set the font to use.
        canvas.Font = bt_font;

        DrawBGBoxes(canvas);
        DrawCrosshair(canvas);
        DrawHealth(canvas);
        DrawAmmo(canvas);
        DrawKills(canvas);
        DrawTimeLeft(canvas);
    }
}


// Draw the HUD background boxes
function DrawBGBoxes(Canvas Canvas)
{
    // Draw the background boxes
    Canvas.Style = ERenderStyle.STY_Alpha;
    Canvas.DrawColor = WhiteColor;

    Canvas.SetPos(-5, -10);
	Canvas.DrawTileStretched(BoxMaterial, canvas.ClipX * 0.325+5, canvas.ClipY/10);

	Canvas.SetPos(canvas.ClipX * 0.325, -10);
	Canvas.DrawTileStretched(BoxMaterial, canvas.ClipX * 0.35, canvas.ClipY/7);

	Canvas.SetPos(canvas.ClipX * 0.675, -10);
	Canvas.DrawTileStretched(BoxMaterial, canvas.ClipX * 0.325+5, canvas.ClipY/10);
}

// Draw the crosshair in center of screen.
function DrawCrosshair(Canvas Canvas)
{
    // Only draw if the weapon exists, if no weapon, no crosshair.
    if (Level.GetLocalPlayerController().Pawn.Weapon != none)
    {
        // SizeX returns size of screen so from that we work out
        // the center of screen in X and Y.
        Canvas.DrawColor = WhiteColor;
        Canvas.SetPos((canvas.SizeX/2)-32,canvas.SizeY/2-32);
        Canvas.DrawIcon(bt_crosshair,1.0);
    }
}

// Draw the health on the screen, icon and text value.
function DrawHealth(Canvas Canvas)
{
    local string HealthString;
    // Draw the health icon in the top left
    Canvas.DrawColor = WhiteColor;
    Canvas.SetPos(10,10);
    Canvas.DrawIcon(bt_health,1.0);

    // Draw the health text, retrieve this from the player.
    Canvas.SetPos(84,18);

    Canvas.DrawColor.R = 200;
    Canvas.DrawColor.G = 20;
    Canvas.DrawColor.B = 20;
    HealthString = ""$Level.GetLocalPlayerController().Pawn.Health;
    HealthString $= "%";
    Canvas.DrawText(HealthString);
}

// Draw the ammo on the screen, icon and text value.
function DrawAmmo(Canvas Canvas)
{
    local float max_ammo, current_ammo;
    local int ammo;

    // Draw icon in mid left
    Canvas.DrawColor = WhiteColor;
    Canvas.SetPos(230,10);
    Canvas.DrawIcon(bt_ammo,1.0);

    // Only display ammo amount if a weapon exists.
    if (Level.GetLocalPlayerController().Pawn.Weapon != none)
    {
        // Retrieve the ammo ammount from the players weapon.
        Level.GetLocalPlayerController().Pawn.Weapon.GetAmmoCount
        (max_ammo,current_ammo );

        ammo = current_ammo;

        // Draw the amount of ammo
        Canvas.DrawColor.R = 200;
        Canvas.DrawColor.G = 20;
        Canvas.DrawColor.B = 20;
        Canvas.SetPos(304,18);
        Canvas.DrawText(ammo);
    }
}


// Draw the kills in the top middle
function DrawKills(Canvas Canvas)
{
    local string ScoreString;
    local int Score;

    // Set the draw color
    canvas.DrawColor.R = 20;
    canvas.DrawColor.G = 20;
    canvas.DrawColor.B = 200;

    Score = PawnOwnerPRI.Score;
    ScoreString = "Kills: "$Score;

    Canvas.SetPos(Canvas.ClipX / 2 - 70, 40);
    Canvas.DrawText(ScoreString);
}


// Draw remaining time in the top right
function DrawTimeLeft(Canvas Canvas)
{
    local int Time;
    local int Minutes, Seconds;
    local string MinStr, SecStr, TimeStr;

    Time = Level.GRI.RemainingTime;
    Minutes = Time / 60;
    Seconds = Time % 60;

    if(Minutes < 10)
    {
        MinStr = "0"$Minutes;
    }
    else
    {
        MinStr = ""$Minutes;
    }

    if(Seconds < 10)
    {
        SecStr = "0"$Seconds;
    }
    else
    {
        SecStr = ""$Seconds;
    }

    TimeStr = MinStr$":"$SecStr;

    canvas.DrawColor.R = 200;
    canvas.DrawColor.G = 200;
    canvas.DrawColor.B = 200;

    Canvas.SetPos(Canvas.ClipX - 200, 18);
    Canvas.DrawText(TimeStr);
}


// Load the textures and font.
defaultproperties
{
    bt_crosshair = texture'BTHud.XHair'
    bt_health = texture'BTHud.Health'
    bt_ammo = texture'BTHud.Ammo'
    bt_font = font'UT2003Fonts.jFontLarge800x600'

    //BoxMaterial=Material'InterfaceContent.BorderBoxD'
    BoxMaterial=Material'InterfaceContent.SquareBoxA'
}
